407A - Triangle - CodeForces Solution


brute force geometry implementation math *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <unordered_map>
 
using namespace std;
 
#define endl '\n'
#define ll long long
#define int long long
#define ld  long double
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 9e18;
const ld PI = acos(-1);
const int MOD = 998244353;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector < int >
#define vii vector < vector < int > >
#define pii pair < int , int >
#define pb push_back


 
int powersOfTwo[31] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
int power(int x, int y){ int r = 1; while(y>0){ if(y&1) r = r * x; y = y >> 1; x = x * x; } return r; }

 
#define loop(i,a,b) for (int i = a; i < b; i++)
#define all(arr) arr.begin(),arr.end()
#define rall(arr) arr.rbegin(),arr.rend()
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define input(arr) for(int i=0;i<arr.size();i++) cin>>arr[i];
#define show(a) {int n=a.size(); for(int i=0;i<a.size();i++) {cout << a[i] << " ";} cout << endl;}
#define nl cout << endl
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------- 


//power function
int binpow(int a, int b, int m) {
    a %= m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//euclidean gcd
ll gcd (ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}

//least common multiple
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

//factorial of n
ll fact(ll n){
    if(n==0)
      return 1;
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = (res * i)%MOD;
    return res;
}

//sieve
vector<int> sieve(int n){
    //int n;
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if(is_prime[i]) prime.pb(i);
        if (is_prime[i] && (long long)i * i <= n) {

            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return prime;
}
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------- 

 



 
int i;
struct values{
  int health,attack,defence;
};

void solution(){
 int a,b;
 cin>>a>>b;
 vii va,vb;
 for(int x=1;x<a;x++){
  int y = sqrt(a*a - x*x);
  if(y*y+x*x == a*a){
    va.pb({x,y});
  }
 }
 for(int x=1;x<b;x++){
  int y = sqrt(b*b - x*x);
  if(y*y+x*x == b*b){
    vb.pb({x,y});
  }
 }
 for(int i=0;i<va.size();i++){
  for(int j=0;j<vb.size();j++){
    //cout<<(va[i][0])<<" "<<va[i][1]<<" "<<vb[i][0]<<" "<<vb[i][1]<<endl;
    if(va[i][0]*vb[j][1] == va[i][1]*vb[j][0]  && vb[j][0]!=va[i][1]){
      cout<<"YES"<<endl;
      cout<<"0 0\n"<<(-1*va[i][0])<<" "<<va[i][1]<<"\n"<<vb[j][1]<<" "<<vb[j][0]<<endl;
      return;
    }
  }
 }
 cout<<"NO"<<endl;
}


int32_t main(){
  fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int tt = 1;
	//cin >> tt;
	while(tt--){
			solution();
	}
	printclock;
}


Comments

Submit
0 Comments
More Questions

Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number